package edu.neu.javaweb.dao;

import edu.neu.javaweb.bean.Employee;
import edu.neu.javaweb.utils.DBUtil;
import io.github.biezhi.anima.Anima;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class EmployeeDao {
//    static Anima anima;
    public List<Employee> findAll(){
        List<Employee> list = new ArrayList<>();
        list = Anima.select().bySQL(Employee.class, "select * from emp_zh").all();
        return list;
    }

    public List<Employee> findById(int id){
        List<Employee> list = new ArrayList<>();
        list = Anima.select().bySQL(Employee.class, "select * from emp_zh where id = ?", id).all();
        return list;
    }

    public void add(Employee emp) {
        Anima.execute("insert into emp_zh values (?,?,?,?,?,?,?,?)",
                emp.getId(),
                emp.getName(),
                emp.getJob(),
                emp.getSal(),
                emp.getHireDate(),
                emp.getMgr(),
                emp.getDeptId(),
                emp.getSex());
    }

    public void deleteById(int id) {
        Anima.execute("delete from emp_zh where id=?" ,id);
    }

    public void update(Employee emp) {
        Anima.execute("update emp_zh set name=?, job=?, hiredate=?, deptid=?, mgr=?, sex=?, sal=? where id=?",
                emp.getName(),
                emp.getJob(),
                emp.getHireDate(),
                emp.getDeptId(),
                emp.getMgr(),
                emp.getSex(),
                emp.getSal(),
                emp.getId()
                );
    }
}
